package com.base;

public enum RoleEnum {

    // 管理员 & 特殊角色（无部门归属）
    ADMIN("ADMIN", "管理员", null, false),
    VISITOR("VISITOR", "游客", null, false),
    USER("USER", "普通用户", null, false),
    CS("cs", "测试", null, false),
    LEADER("leader", "领导", null, true),
    // 部门负责人
    DEPARTMENT_LEADER("department_leader", "部门负责人", null, true),
    // 生产技术部
    PRODUCTION_LEADER("production_leader", "生产部负责人", "production", true),
    PRODUCTION_TECHNOLOGY("production", "生产技术部", "production", false),
    // 技术指挥部
    TECHNICAL_COMMAND("technical_command", "技术指挥部", "technical", true),
    // 测控专业部
    MC_LEADER("mc_leader", "测控专业部负责人", "mc", true),
    MC_DEPARTMENT("mc_department", "测控专业部", "mc", false),
    // 仪表专业部
    INSTRUMENT_LEADER("instrument_leader", "仪表专业部负责人", "instrument", true),
    INSTRUMENT_DEPARTMENT("instrument_department", "仪表专业部", "instrument", false),
    // 综合部
    GENERAL_LEADER("general_leader", "综合部负责人", "general", true),
    GENERAL_DEPARTMENT("general_department", "综合部", "general", false),
    GENERAL_COMMAND("general_command", "综合指挥部", "general", false),
    // 销售部
    SALES_LEADER("sales_leader", "销售部负责人", "sales", true),
    SALES_DEPARTMENT("sales_department", "销售部", "sales", false);

    private final String code;
    private final String description;
    private final String department; // 所属部门标识
    private final boolean isLeader;  // 是否为该部门的领导

    RoleEnum(String code, String description, String department, boolean isLeader) {
        this.code = code;
        this.description = description;
        this.department = department;
        this.isLeader = isLeader;
    }

    // 根据编码获取枚举
    public static RoleEnum fromCode(String code) {
        for (RoleEnum role : values()) {
            if (role.getCode().equalsIgnoreCase(code)) {
                return role;
            }
        }
        throw new IllegalArgumentException("Invalid role code: " + code);
    }

    // 获取角色所属部门
    public String getDepartment() {
        return department;
    }

    public boolean isLeader() {
        return isLeader;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }
}